######### FINE IMPORTS FROM THE WORLD#########
import configparser
import os

############# THE CLASS ###########
class Configit:
    initconfig = 0
    configstuff = configparser.ConfigParser()
    configstuff['MAIN'] = {'dbusername': 'root', 'dbpass': '', 'port': '50007', 'dbport':'3306', 'dbhost':'localhost'}
    portcfg = 0
    dbpas = ""
    dbuser = ""
    dbhost = ""
    dbport = 0
    servport = 50007

    
    def __init__(self):
        
        
        if os.path.isfile('./sitting.ini'):
            
            print('LOADING EXISTING FILE' + '\n')
            
            self.configstuff.read('sitting.ini')
            self.portcfg = int(self.configstuff.get('MAIN', 'port'))
            self.dbpas = str(self.configstuff.get('MAIN', 'dbpass'))
            self.dbuser = str(self.configstuff.get('MAIN', 'dbusername'))
            self.dbport = int(self.configstuff.get('MAIN', 'dbport'))
            self.dbhost = str(self.configstuff.get('MAIN', 'dbhost'))
        

        else:
            print('Settings File Does Not Exist, writing one with defaults'+ '\n')
            if self.initconfig == 1:
                self.configstuff['MAIN']['dbpass'] = input("DB Password: "+"\n")
            cfgfile = open('sitting.ini','w')
            self.configstuff.write(cfgfile)
            cfgfile.close()
            self.configstuff.read('sitting.ini')
            self.portcfg = int(self.configstuff.get('MAIN', 'port'))
            self.dbpas = str(self.configstuff.get('MAIN', 'dbpass'))
            self.dbuser = str(self.configstuff.get('MAIN', 'dbusername'))
            self.dbhost = str(self.configstuff.get('MAIN', 'dbhost'))
            self.dbport = int(self.configstuff.get('MAIN', 'dbport'))
            #print('Due to issues, edit the ini file manually with password')
            #quit()

    def configfilechecker():
        #Creates config file if it doesn't exist, sets some defaults
        pass
    def setdbpass():
        #if db password doesn't exist, gets input
        #if it does, does nothing!
        dbhold = input("DB password: ")
        self.dbpas = dbhold

        
    def resetdbpass():
        #allows you to reset db pass.
        pass
    def loadconfig():
        pass
    def saveconfig():
        #might... not need?

        pass

    def setconfigval(value):
        #possible single value change
        value = valueA
        pass
    
class Menu:
    state = 0
    command ={'1':1,'2':2,'3':3,'4':4,'q':999}
        
        
    intmenu = "Start server: 1, nothing yet: 2,3, 4, quit: q"

    def display(self):
        # Displays the menu choices
            
                
        print(self.intmenu)
                
    def ginput(self):
        #gets user choice
        letter = input("Choice: ")
        while letter not in self.command:
            letter = input("Choice: ")
        self.state = self.command[letter]
    def returntomenu(self):
        #Brings us back to the menu
            
              
        self.state = 0
        return self.state
